import numpy as np

# 汇率数据（已按日期排序）
exchange_rates = [
    {"date": "2024-12-16", "price": 7.1882},
    {"date": "2024-12-17", "price": 7.1891},
    {"date": "2024-12-18", "price": 7.188},
    {"date": "2024-12-19", "price": 7.1911},
    {"date": "2024-12-20", "price": 7.1901},
    {"date": "2024-12-20", "price": 8}
]

# 贵金属数据（已按日期排序，并假设与汇率数据日期匹配）
precious_metals = [
    {"date": "2024-12-16", "currentPrice": 619.45},
    {"date": "2024-12-17", "currentPrice": 618.12},
    {"date": "2024-12-18", "currentPrice": 617.19},
    {"date": "2024-12-19", "currentPrice": 616.03},
    {"date": "2024-12-20", "currentPrice": 608.71},
    {"date": "2024-12-21", "currentPrice": 606.71}
]

# 选择基准日期（这里选择第一个日期）
base_date = exchange_rates[0]["date"]
base_exchange_rate = exchange_rates[0]["price"]
base_metal_price = [item for item in precious_metals if item["date"] == base_date][0]["currentPrice"]

# 数据标准化
standardized_exchange_rates = [(rate["price"] / base_exchange_rate) for rate in exchange_rates]
standardized_metal_prices = [(metal["currentPrice"] / base_metal_price) for metal in precious_metals]

# 计算加权平均值（这里使用等权重）
weights = [0.1, 0.9]
combined_values = [w1 * ex + w2 * met for ex, met, w1, w2 in zip(standardized_exchange_rates, standardized_metal_prices, [weights[0]]*len(standardized_exchange_rates), [weights[1]]*len(standardized_metal_prices))]

# 计算波动幅度
max_combined_value = max(combined_values)
min_combined_value = min(combined_values)
fluctuation_amplitude = (max_combined_value - min_combined_value) / ((max_combined_value + min_combined_value) / 2)  # 使用相对波动幅度公式

# 评分
if -0.1 <= fluctuation_amplitude <= 0.1:
    score = 4
elif -0.2 <= fluctuation_amplitude <= 0.2:
    score = 2
else:
    score = 0

# 输出结果
print(f"综合金融市场数据波动幅度: {fluctuation_amplitude:.4%}")
print(f"综合得分: {score}")